home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / common / UpdateMixin.pyo (.txt) < prev   
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  80 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from logging import getLogger
  5. log = getLogger('updatemixin')
  6. info = log.info
  7. from Protocol import StateMixin
  8. from util import Delegate, RepeatTimer, get
  9.  
  10. nothing = lambda *a, **k: pass
  11.  
  12. class UpdateMixin(StateMixin):
  13.     updatefreq = 300
  14.     
  15.     def __init__(self, updatefreq = None, *a, **k):
  16.         StateMixin.__init__(self, *a, **k)
  17.         if updatefreq is not None:
  18.             
  19.             try:
  20.                 updatefreq = int(updatefreq)
  21.             except ValueError:
  22.                 pass
  23.  
  24.             if updatefreq < 1:
  25.                 updatefreq = 60
  26.             
  27.             self.updatefreq = max(updatefreq, 15)
  28.         
  29.         self.on_connect = Delegate()
  30.         self.on_disable = Delegate()
  31.  
  32.     
  33.     def disconnect(self):
  34.         self.timer.stop()
  35.  
  36.     
  37.     def update_now(self):
  38.         raise NotImplementedError
  39.  
  40.     
  41.     def get_options(self):
  42.         return (dict,)((lambda .0: for a in .0:
  43. (a, getattr(self, a)))(('enabled', 'updatefreq')))
  44.  
  45.     
  46.     def get_enabled(self):
  47.         return get(self, '_enabled', False)
  48.  
  49.     
  50.     def set_enabled(self, value):
  51.         if not hasattr(self, '_enabled'):
  52.             self.change_reason(self.Reasons.NONE)
  53.             info('%s creating a timer with update frequency %s', self, self.updatefreq)
  54.             self.timer = RepeatTimer(int(self.updatefreq), self.update_now)
  55.             self.timer.start()
  56.             self.timer.stop()
  57.             if get(self, 'on_connect', None) is not None and self.update_now not in self.on_connect:
  58.                 self.on_connect += self.update_now
  59.             
  60.         
  61.         if value:
  62.             info('enabling timer for %s', self)
  63.             if self.OFFLINE:
  64.                 get(self, 'Connect', nothing)()
  65.             
  66.             self.timer.reset(int(self.updatefreq))
  67.             self._enabled = value
  68.         elif hasattr(self, '_enabled'):
  69.             if not self.OFFLINE:
  70.                 get(self, 'Disconnect', nothing)()
  71.             
  72.             info('stopping timer for %s', self)
  73.             self.timer.stop()
  74.             get(self, 'on_disable', nothing)()
  75.         
  76.         self._enabled = value
  77.  
  78.     enabled = property(get_enabled, set_enabled)
  79.  
  80.